<%-- 
    Document   : display_cart
    Created on : Jan 13, 2012, 2:36:46 PM
    Author     : Fernando
--%>

<%@page import="com.sdd.plains.ProductPlain"%>
<%@page import="com.sdd.plains.CartItem"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.sdd.plains.CartPlain"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
            <input type="submit" value="Save Changes" id="saveCart" onclick="editCart()"/>
            <input type="submit" value="Check out" id="checkOut" onclick="getPage('checkout_form.jsp')"/>
            <div class="cart-item-head">
                <table>
                    <tr>
                        <td class="thd1">Items to buy now</td>
                        <td class="thd2">Price</td>
                        <td class="thd3">Quantity</td>
                    </tr>
                </table>
            </div>
            <br />
            <hr />
<%
    CartPlain cart = (CartPlain) request.getSession().getAttribute("cart");
    Double count = 0.0;
    int numOfProducts = 0;
    if(cart != null) {
        Iterator it = cart.iterator();
        CartItem ci;
        ProductPlain p;        
        while(it.hasNext()) {
            numOfProducts++;
            ci = (CartItem) it.next();
            p = ci.getProduct();
            count += ci.getQuantity()*p.getPrice();
%>
            <div class="cart-produc-list">
                <table><tr>
                    <td class="td1" valign="top"><img src="img/stewie.jpg" width="100" height="100" onclick="viewProduct('<%=p.getProductId()%>')"/></td>
                    <td class="td2" valign="top">
                        <p onclick="viewProduct('<%=p.getProductId()%>')"><%=p.getName()%></p>
                    </td>
                    <td class="td3" valign="top">
                        <p><%=p.getPrice()%> &euro;</p>
                    </td>
                    <td class="td4" valign="top">
                        <p><input type="text" id="pc<%=p.getProductId()%>" size="3" maxlength="3" value="<%=ci.getQuantity()%>"></p>
                           <input type="hidden" id="p<%=numOfProducts%>" value="<%=p.getProductId()%>">
                    </td>
                </tr></table>    
            </div>
<%
        }
    }
%>          <hr />
            <input type="hidden" id="count" value="<%=numOfProducts%>">
            <div class="cart-item-head">
                <table>
                    <tr>
                        <td class="thd1"><b>Total:</b></td>
                        <td class="thd2"><h3><%=count%> &euro;</h3></td>
                        <td class="thd3"></td>
                    </tr>
                </table>
            </div>